package com.probiz.estore.imports.handler.customer;

import org.apache.commons.lang.StringUtils;

import com.probiz.estore.common.helper.ConfigUtil;
import com.probiz.estore.common.model.customer.Customer;
import com.probiz.estore.core.util.StringUtil;
import com.probiz.estore.customer.service.CustomerManager;
import com.probiz.estore.imports.handler.ColumnHandler;
import com.probiz.estore.imports.handler.basic.ColumnBasicHandler;
import com.probiz.estore.imports.model.Column;
import com.probiz.estore.imports.model.ImportModel;

public class PasswordHandler extends ColumnBasicHandler implements ColumnHandler {

	private CustomerManager customerManager;

	public void setCustomerManager(CustomerManager customerManager) {
		this.customerManager = customerManager;
	}

	public void setProperty(ImportModel importModel, Column column)	throws Exception {
		Customer customer = (Customer)importModel.getTarget();
		String value = column.getValue();
		if(null == customer.getAppuserId()){
			if(!StringUtils.isBlank(value)){
				customer.setPassword(StringUtil.encodePassword(value, ConfigUtil.getInstance().getPasswordEncryptionAlgorithm()));
			}else{
				customer.setPassword(StringUtil.encodePassword(ConfigUtil.getInstance().getCustomerImportDefaultPassword(), ConfigUtil.getInstance().getPasswordEncryptionAlgorithm()));
			}
		}	
		//设置结果
		importModel.setResult(ImportModel.RESULT_SUCCESS);
	}

}
